﻿using JinianNet.JNTemplate;
using log4net;
using log4net.Appender;
using log4net.Config;
using log4net.Layout;
using log4net.Repository.Hierarchy;
using System;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Xml.Linq;

namespace WebSelfHost.Utility.Logs
{
    public class LogHelper
    {
        public static readonly ILog loginfo = LogManager.GetLogger("loginfo");
        public static readonly ILog logerror = LogManager.GetLogger("logerror");
        public static readonly ILog logoperate = LogManager.GetLogger("logoperate");

        public static void Init(string configContent)
        {
            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(configContent));
            XmlConfigurator.Configure(stream);
        }

        public static void Info(string message)
        {
            if (loginfo.IsInfoEnabled)
            {
                loginfo.Info(message);
            }
        }

        public static void Info(string message, Exception ex)
        {
            if (loginfo.IsInfoEnabled)
            {
                loginfo.Info(message, ex);
            }
        }

        public static void Operate(string message)
        {
            if (logoperate.IsDebugEnabled)
            {
                logoperate.Debug(message);
            }
        }
        public static void Operate(string message, Exception ex)
        {
            if (logoperate.IsDebugEnabled)
            {
                logoperate.Debug(message, ex);
            }
        }

        public static void Error(string message)
        {
            if (logerror.IsErrorEnabled)
            {
                logerror.Error(message);
            }
        }

        public static void Error(string message, Exception ex)
        {
            if (logerror.IsErrorEnabled)
            {
                logerror.Error(message, ex);
            }
        }
    }

    public enum Level
    {
        [Description("普通输出")]
        Trace,
        [Description("一般调试")]
        Debug,
        [Description("普通消息")]
        Info,
        [Description("警告信息")]
        Warn,
        [Description("一般错误")]
        Error,
        [Description("致命错误")]
        Fatal
    }
}
